home *** CD-ROM | disk | FTP | other *** search
/ Champak 26 (Anniversary Edition) / Volume 26 [Anniversary Edition] - JOGO DISK .iso / Puzzle / allout.swf / scripts / frame_3 / DoAction.as
Text File  |  2006-05-29  |  9KB  |  289 lines

  1. function TurnOn()
  2. {
  3.    y = 1;
  4.    while(5 >= y)
  5.    {
  6.       x = 1;
  7.       while(5 >= x)
  8.       {
  9.          this["h" + x + y].gotoAndStop("oncomplete");
  10.          x++;
  11.       }
  12.       y++;
  13.    }
  14. }
  15. function Click(x, y)
  16. {
  17.    holestatinc = 0;
  18.    xvals = new Array(-1,1,0,0);
  19.    yvals = new Array(0,0,-1,1);
  20.    moves++;
  21.    j = 0;
  22.    while(j < 4)
  23.    {
  24.       nx = x + xvals[j];
  25.       ny = y + yvals[j];
  26.       mc = "h" + nx + ny;
  27.       if(this[mc]._x)
  28.       {
  29.          this[mc].Swap();
  30.       }
  31.       j++;
  32.    }
  33.    if(!resetbutton.reset)
  34.    {
  35.       resetbutton.gotoAndStop(2);
  36.    }
  37.    if(PuzzleSolved())
  38.    {
  39.       if(0 < solver.count)
  40.       {
  41.          stop();
  42.       }
  43.       else
  44.       {
  45.          gotoAndPlay(137);
  46.       }
  47.    }
  48. }
  49. function ReadPuzzle(wp)
  50. {
  51.    var puzzlines = new Array();
  52.    puzzlines = puzzles[wp].split("|");
  53.    j = 0;
  54.    while(j < 5)
  55.    {
  56.       puzzarray[j] = new Array();
  57.       puzzarray[j] = puzzlines[j].split(",");
  58.       j++;
  59.    }
  60. }
  61. function PuzzleSolved()
  62. {
  63.    y = 0;
  64.    while(4 >= y)
  65.    {
  66.       x = 0;
  67.       while(4 >= x)
  68.       {
  69.          if(puzzarray[y][x] == 1)
  70.          {
  71.             return 0;
  72.          }
  73.          x++;
  74.       }
  75.       y++;
  76.    }
  77.    solved = true;
  78.    return 1;
  79. }
  80. function ShowPuzzle()
  81. {
  82.    solver.stop();
  83.    solved = false;
  84.    moves = 0;
  85.    holestatinc = 1;
  86.    holestats = 0;
  87.    var x;
  88.    var y;
  89.    var knob;
  90.    y = 0;
  91.    while(y < 5)
  92.    {
  93.       x = 0;
  94.       while(x < 5)
  95.       {
  96.          knob = "h" + (x + 1) + (y + 1);
  97.          if(puzzarray[y][x] == 1 && this[knob].status == 0)
  98.          {
  99.             this[knob].gotoAndPlay("on");
  100.             holestats++;
  101.          }
  102.          if(puzzarray[y][x] == 0 && this[knob].status == 1)
  103.          {
  104.             this[knob].gotoAndPlay("off");
  105.             holestats++;
  106.          }
  107.          if(this[knob].solution == 1)
  108.          {
  109.             this[knob].base.gotoAndPlay("solutionoff");
  110.          }
  111.          x++;
  112.       }
  113.       y++;
  114.    }
  115.    timer.startTime = getTimer();
  116.    activebuttons = true;
  117.    resetbutton.gotoAndStop(1);
  118.    solvebutton.gotoAndStop(1);
  119.    randombutton.gotoAndStop(1);
  120.    _parent.activebuttons = true;
  121. }
  122. function Reset()
  123. {
  124.    y = 1;
  125.    while(5 >= y)
  126.    {
  127.       x = 1;
  128.       while(5 >= x)
  129.       {
  130.          this["h" + x + y].base.gotoAndStop(1);
  131.          x++;
  132.       }
  133.       y++;
  134.    }
  135. }
  136. function SolvePuzzle()
  137. {
  138.    var hint = new Array();
  139.    hint[0] = new Array(0,1,1,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0);
  140.    hint[1] = new Array(1,1,0,1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0);
  141.    hint[2] = new Array(1,0,1,1,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1,1,0,1,0);
  142.    hint[3] = new Array(1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1);
  143.    hint[4] = new Array(0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,1,1,0);
  144.    hint[5] = new Array(0,0,1,0,1,0,1,1,0,1,0,0,1,0,0,0,0,0,1,1,0,0,0);
  145.    hint[6] = new Array(0,1,0,1,0,1,1,0,1,1,0,0,0,1,0,1,1,1,0,0,0,1,0);
  146.    hint[7] = new Array(1,0,1,0,0,1,0,1,1,0,0,0,0,0,1,1,0,1,0,1,1,0,1);
  147.    hint[8] = new Array(0,0,1,0,0,0,1,1,1,0,1,0,0,1,1,1,0,0,1,0,0,1,1);
  148.    hint[9] = new Array(1,0,0,0,0,1,1,0,0,0,1,0,1,0,1,0,1,1,0,1,0,0,1);
  149.    hint[10] = new Array(0,0,0,0,1,0,0,0,1,1,0,0,1,0,1,1,1,1,1,0,0,1,0);
  150.    hint[11] = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1);
  151.    hint[12] = new Array(0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,0,0,1,1,0);
  152.    hint[13] = new Array(1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,0,0,0,1,0,0,0,0);
  153.    hint[14] = new Array(1,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,0,1,0,1,0,0);
  154.    hint[15] = new Array(0,0,1,0,0,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,1);
  155.    hint[16] = new Array(0,0,1,1,0,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,0,0,1);
  156.    hint[17] = new Array(0,0,1,0,1,0,1,1,0,1,1,0,1,0,0,1,1,0,1,1,1,0,0);
  157.    hint[18] = new Array(0,1,1,0,0,1,0,0,1,0,1,0,0,1,1,0,1,1,1,0,0,0,1);
  158.    hint[19] = new Array(1,0,1,0,1,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,1);
  159.    hint[20] = new Array(0,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,0,1,0,1,1,1,0);
  160.    hint[21] = new Array(0,0,1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1);
  161.    hint[22] = new Array(0,0,0,1,0,0,0,1,1,1,0,1,0,0,0,1,1,0,1,1,0,1,0);
  162.    goal = new Array();
  163.    j = 0;
  164.    while(j < 5)
  165.    {
  166.       goal[j] = new Array(0,0,0,0,0);
  167.       j++;
  168.    }
  169.    var current_state = new Array();
  170.    var hint_vector = new Array();
  171.    i = 0;
  172.    while(i < 23)
  173.    {
  174.       hint_vector[i] = 0;
  175.       if(puzzarray[i % 5][int(i / 5)] == 0)
  176.       {
  177.          current_state[i] = 0;
  178.       }
  179.       else
  180.       {
  181.          current_state[i] = 1;
  182.       }
  183.       i++;
  184.    }
  185.    i = 0;
  186.    while(i < 23)
  187.    {
  188.       j = 0;
  189.       while(j < 23)
  190.       {
  191.          hint_vector[i] = (hint_vector[i] + current_state[j] * hint[i][j]) % 2;
  192.          j++;
  193.       }
  194.       i++;
  195.    }
  196.    i = 0;
  197.    while(i < 23)
  198.    {
  199.       goal[i % 5][int(i / 5)] = hint_vector[i];
  200.       i++;
  201.    }
  202.    Reset();
  203. }
  204. function ShowSolution()
  205. {
  206.    y = 0;
  207.    while(y < 5)
  208.    {
  209.       x = 0;
  210.       while(x < 5)
  211.       {
  212.          if(goal[y][x] == 1)
  213.          {
  214.             this["h" + (x + 1) + (y + 1)].base.gotoAndPlay("solutionon");
  215.          }
  216.          else
  217.          {
  218.             this["h" + (x + 1) + (y + 1)].base.gotoAndStop(1);
  219.          }
  220.          x++;
  221.       }
  222.       y++;
  223.    }
  224. }
  225. activebuttons = false;
  226. puzzarray = new Array();
  227. puzzles = new Array();
  228. puzzles[1] = "1,1,0,1,1|1,0,1,0,1|0,1,1,1,0|1,0,1,0,1|1,1,0,1,1";
  229. puzzles[2] = "0,1,0,1,0|1,1,0,1,1|0,1,0,1,0|1,0,1,0,1|1,0,1,0,1";
  230. puzzles[3] = "1,0,0,0,1|1,1,0,1,1|0,0,1,0,0|1,0,1,0,0|1,0,1,1,0";
  231. puzzles[4] = "1,1,0,1,1|0,0,0,0,0|1,1,0,1,1|0,0,0,0,1|1,1,0,0,0";
  232. puzzles[5] = "1,1,1,1,1|1,1,1,1,1|1,1,1,1,1|1,1,1,1,1|1,1,1,1,1";
  233. puzzles[6] = "0,1,1,1,0|1,0,0,0,1|1,0,1,0,1|1,0,0,0,1|0,1,1,1,0";
  234. puzzles[6] = "0,0,0,1,1|0,0,0,1,1|0,0,0,0,0|1,1,0,0,0|1,1,0,0,0";
  235. puzzles[7] = "0,0,0,0,0|0,1,1,1,0|1,1,1,1,1|0,1,1,1,0|0,0,0,0,0";
  236. puzzles[8] = "0,0,0,0,0|0,1,1,1,0|0,1,1,1,0|0,1,1,1,0|0,0,0,0,0";
  237. puzzles[9] = "1,1,0,1,1|1,1,0,1,1|0,0,0,0,0|1,1,0,1,1|1,1,0,1,1";
  238. puzzles[10] = "1,1,1,1,1|0,1,1,1,0|0,0,1,0,0|0,1,1,1,0|1,1,1,1,1";
  239. puzzles[11] = "1,1,1,1,1|1,0,0,0,1|1,0,0,0,1|1,0,0,0,1|1,1,1,1,1";
  240. puzzles[12] = "0,0,1,1,1|0,0,0,1,1|1,0,0,0,1|1,1,0,0,0|1,1,1,0,0";
  241. puzzles[13] = "1,0,0,0,1|0,1,0,1,0|0,0,1,0,0|0,1,0,1,0|1,0,0,0,1";
  242. puzzles[14] = "1,1,1,1,1|1,0,1,0,1|1,1,1,1,1|1,0,1,0,1|1,1,1,1,1";
  243. puzzles[15] = "1,0,0,0,0|1,1,1,1,0|1,1,1,1,0|1,1,1,1,0|1,1,1,1,1";
  244. puzzles[16] = "1,1,1,1,1|1,1,1,1,1|1,1,0,1,1|1,1,1,1,1|1,1,1,1,1";
  245. puzzles[17] = "1,0,1,0,1|0,1,0,1,0|0,0,1,0,0|0,1,0,1,0|1,0,1,0,1";
  246. puzzles[18] = "1,1,1,0,1|1,1,1,0,1|0,0,0,0,0|1,0,1,1,1|1,0,1,1,1";
  247. puzzles[19] = "1,1,0,1,1|1,1,0,1,1|1,1,0,1,1|1,1,0,1,1|1,1,0,1,1";
  248. puzzles[20] = "1,1,1,1,1|1,0,0,0,1|1,1,0,1,1|1,1,0,1,1|1,1,1,1,1";
  249. puzzles[21] = "1,1,1,1,1|1,1,1,1,1|0,0,0,1,1|0,0,0,1,1|0,0,0,1,1";
  250. puzzles[22] = "1,1,1,0,1|1,1,1,0,0|1,1,1,0,0|1,1,1,0,0|1,1,1,0,1";
  251. puzzles[23] = "1,1,1,1,1|0,0,1,0,0|0,0,1,0,0|0,0,1,0,0|1,1,1,1,1";
  252. puzzles[24] = "0,0,0,0,0|0,1,1,0,0|0,1,1,1,0|0,0,1,1,0|0,0,0,0,0";
  253. puzzles[25] = "0,0,0,1,1|0,0,1,1,1|0,0,1,0,0|1,1,1,0,0|1,1,0,0,0";
  254. puzzles[26] = "0,0,0,1,1|1,1,0,1,1|1,1,0,0,0|1,1,0,0,0|1,1,0,1,1";
  255. puzzles[27] = "1,0,0,0,1|0,1,1,1,0|0,1,1,1,0|0,1,1,1,0|1,0,0,0,1";
  256. puzzles[28] = "1,0,1,0,1|0,1,0,1,0|1,0,1,0,1|0,1,0,1,0|1,0,1,0,1";
  257. puzzles[29] = "0,0,1,0,0|1,0,0,1,0|0,1,1,1,1|1,0,0,0,0|1,1,0,1,0";
  258. puzzles[30] = "0,0,0,0,1|0,0,0,1,1|0,0,1,0,1|0,1,0,0,1|1,1,1,1,1";
  259. puzzles[31] = "1,1,0,1,1|0,1,0,1,0|1,1,1,1,1|1,1,0,1,1|1,0,0,0,1";
  260. puzzles[32] = "0,1,1,0,0|0,1,1,0,1|0,1,0,0,1|1,1,0,0,0|1,1,1,1,0";
  261. puzzles[33] = "0,0,0,0,1|1,1,1,0,0|1,0,1,1,1|1,1,1,1,0|1,0,0,1,0";
  262. puzzles[34] = "1,0,1,1,1|0,0,1,0,1|0,0,0,0,0|1,1,1,1,0|1,1,0,1,0";
  263. puzzles[35] = "1,1,0,1,1|0,1,0,1,1|0,0,0,1,0|1,1,0,0,0|1,1,1,1,0";
  264. puzzles[36] = "1,1,1,1,1|0,0,0,1,0|0,1,0,1,1|1,1,1,0,1|1,0,1,0,0";
  265. puzzles[37] = "0,0,0,1,1|1,0,1,1,0|0,0,1,0,0|0,1,1,1,1|1,0,0,1,0";
  266. puzzles[38] = "0,0,0,0,1|0,0,1,1,1|1,1,0,0,1|1,1,1,0,0|0,0,1,0,0";
  267. puzzles[39] = "0,0,1,1,1|1,0,1,1,1|1,1,1,0,0|0,0,1,0,0|1,1,0,1,1";
  268. puzzles[40] = "0,1,1,1,1|0,0,1,1,1|0,0,1,1,1|1,1,1,1,0|0,0,0,1,0";
  269. puzzles[41] = "1,1,1,1,1|1,0,0,0,0|0,1,0,0,1|0,0,0,1,1|1,1,1,1,1";
  270. puzzles[42] = "1,1,1,1,1|1,0,0,0,0|0,0,1,0,0|0,1,1,1,0|0,1,0,0,1";
  271. puzzles[43] = "0,0,0,0,0|0,0,0,1,0|1,1,0,1,1|0,1,1,0,0|1,1,1,1,1";
  272. puzzles[44] = "0,0,0,1,1|0,1,1,0,0|0,1,0,0,0|1,1,1,1,0|1,1,1,1,0";
  273. puzzles[45] = "0,0,0,1,0|1,1,1,1,1|0,0,0,0,0|0,0,1,0,0|1,1,1,1,0";
  274. puzzles[46] = "0,1,0,1,0|0,0,0,1,0|0,1,0,1,0|0,0,1,0,0|0,1,1,1,0";
  275. puzzles[47] = "1,0,0,1,0|0,0,0,0,1|0,1,0,0,0|0,0,0,0,0|1,0,1,0,0";
  276. puzzles[48] = "1,1,0,0,1|0,1,0,0,1|0,1,1,1,1|0,1,0,1,0|1,1,1,1,1";
  277. puzzles[49] = "1,1,1,1,1|0,0,1,0,0|0,1,1,0,0|0,0,1,1,0|1,1,1,0,1";
  278. puzzles[50] = "1,0,1,0,1|1,0,1,0,0|0,0,0,1,1|0,1,0,1,0|1,0,0,1,0";
  279. puzzles[51] = "0,1,0,1,0|1,0,0,1,0|0,1,1,1,1|1,0,1,0,0|0,1,1,0,0";
  280. puzzles[52] = "1,1,1,1,1|1,1,0,0,0|0,0,0,1,1|0,1,1,1,0|0,0,1,0,0";
  281. puzzsize = puzzles.length - 1;
  282. chooser.levelnum = 1;
  283. popSound = new Sound();
  284. popSound.attachSound("pop");
  285. winSound = new Sound();
  286. winSound.attachSound("winsound");
  287. lewbeep = new Sound();
  288. lewbeep.attachSound("lewbeep");
  289.